<%@page import="com.mde.util.Validator"%>
<%@page import="org.apache.catalina.connector.Request"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%!	
	Statement stmt;
	Connection con;
	String url = Validator.dbURL;	
%>	
<%
	String query = "SELECT routeId FROM Routes WHERE name = \"" + 
			request.getParameter("routeName") + "\";";
			
	Class.forName("com.mysql.jdbc.Driver");
	con = DriverManager.getConnection(url, "root", "12345"); 
	stmt = con.createStatement();
	
	ResultSet rs = stmt.executeQuery(query);
	int id = rs.next() ? rs.getInt("routeId") : -1;
	if (id == -1) {
		out.println("No route with such name");
		return;
	}
	
	try {
		stmt.execute("DELETE FROM Routes WHERE routeId = " + id + ";");
		stmt.execute("DELETE FROM Edges WHERE routeId = " + id + ";");
		out.println("Route successfully deleted!");
	} catch (Exception e) {
		out.println("an error occured");
	}

%>

</body>
</html>